package com.hjp.redis.redistemplate.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * @Author: huangjp6
 * @Description:
 * @Date: 2021/8/24 18:01
 */
@RestController
@RequestMapping("/hello")
public class HelloWorldController {

    @Autowired
    private HashOperations<String, String, Object> hashOperations;

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @RequestMapping("/say")
    public String say() {
        HashMap hashMap = new HashMap();
        hashMap.put("A", "A1");
        hashMap.put("B", "B1");
        hashOperations.putAll("hello_key", hashMap);
        Long hello_key = hashOperations.size("hello_key");
        return "Hello World hello_key size =" + hello_key;
    }

    // StringRedisTemplate和RedisTemplate区别见redis.md
}